<div class="content-wrapper">
    <section class="content-header">
        <h1>新入库</h1>
        <ol class="breadcrumb">
            <li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">客户管理</li>
            <li class="active"><a href="/admin/itemCate/cateList">客户列表</a></li>
            <li class="active">需求明确</li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-header with-border">
            </div>
            <div class="box-body">
                <form class="form-horizontal" role="form" action="javascrip:;" method="post">
                    <input type="hidden" name="id" id="id" value="{$customer.id}" />
                    <div class="form-group">
                        <label for="level" class="col-sm-3 control-label"> 客户级别 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="level" name="level">
                                <option value="1" <if condition="$customer.level eq 1 ">selected</if>>非常重要</option>
                                <option value="2" <if condition="$customer.level eq 2 ">selected</if>>比较重要</option>
                                <option value="3" <if condition="$customer.level eq 3 ">selected</if>>一般</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="type" class="col-sm-3 control-label"> 客户类别 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="type" name="type">
                                <foreach name="regimentation" item="p">
                                    <option value="{$p.id}" <if condition="$p.id eq $customer.type ">selected</if>>{$p.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="company_name" class="col-sm-3 control-label"> 公司名称<span style="color: #f00;">*</span> </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="company_name" name="company_name" value="{$customer.company_name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="product_name" class="col-sm-3 control-label"> 推广产品<span style="color: #f00;">*</span> </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="product_name" name="product_name" value="{$customer.product_name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="name" class="col-sm-3 control-label"> 联系人<span style="color: #f00;">*</span> </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="name" name="name" value="{$customer.name}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="mobile" class="col-sm-3 control-label"> 手机号<span style="color: #f00;">*</span> </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="mobile" name="mobile" value="{$customer.mobile}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tel" class="col-sm-3 control-label"> 固话 </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="tel" name="tel" value="{$customer.tel}" placeholder="0101-4088888">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="wechat" class="col-sm-3 control-label"> 微信 </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="wechat" name="wechat" value="{$customer.wechat}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="qq" class="col-sm-3 control-label"> QQ </label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="qq" name="qq" value="{$customer.qq}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="cid" class="col-sm-3 control-label"> 选择产品一级名称 </label>
                        <div class="col-sm-6">
                            <select class="form-control" id="cid" name="cid" onchange="change_cid(this.value)">
                                <foreach name="p_cate" item="p">
                                    <option value="{$p.id}" <if condition="$p.id eq $customer.cid ">selected</if>>{$p.name}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>

                    <hr style="border: 1px solid #dcdcdc;margin: 30px auto;"/>
                    <h4>需求明确</h4>
                    <div class="form-group">
                        <label for="second_cid" class="col-sm-3 control-label"> 选择产品二级名称 </label>
                        <div class="col-sm-2">
                            <select class="form-control" id="second_cid" name="second_cid">
                                <foreach name="second_cate" item="p">
                                    <option value="{$p.id}" <if condition="$p.id eq $customer.second_cid ">selected</if>>{$p.name}</option>
                                </foreach>
                            </select>
                        </div>
                        <label for="three_cid" class="col-sm-2 control-label"> 选择产品三级名称 </label>
                        <div class="col-sm-2">
                            <select class="form-control" id="three_cid" name="three_cid">
                                <option></option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 50px;">
                        <label for="form-field-1" class="col-sm-3 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-sm" style="margin-right: 50px;" data-toggle="modal" data-target="#myModal">终止服务</button>
                            <button type="button" class="btn btn-info btn-sm save-btn">提交保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<!--终止服务-->
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="margin-top: 200px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">终止服务备注</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" name="customer_id" id="customer_id" value="{$customer.id}">
                <textarea name="refuse_reason" id="refuse_reason" style="width: 100%;height: 100px;margin: auto;">

                </textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default refuse_customer" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="update">确认</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script type="application/javascript">
    //保存用户
    $(".save-btn").click(function(){
        var preg = /^1[34578]\d{9}$/; //手机号
        var preg_tel = /^0\d{2,3}-\d{7,8}$/;
        var id = $("#id").val();
        var name = $.trim($("#name").val());
        var cid = $("#cid").val();
        var company_name = $("#company_name").val();
        var product_name = $("#product_name").val();
        var mobile = $("#mobile").val();
        var type = $('#type').val();
        var level = $('#level').val();
        var tel = $('#tel').val();
        var wechat = $('#wechat').val();
        var qq = $('#qq').val();
        var second_cid = $('#second_cid').val();

        if(name == '') {
            ArtDialogHlp.showInfo('提示', '请填写联系人');
            return false;
        }
        if(company_name == ''){
            ArtDialogHlp.showInfo('提示', '请填写公司名称');
            return false;
        }
        if(product_name == ''){
            ArtDialogHlp.showInfo('提示', '请填写推广产品名称');
            return false;
        }
        if(!preg.test(mobile)){
            ArtDialogHlp.showInfo('提示', '手机号不存在，请重新输入');
            return false;
        }
        if(!preg_tel.test(tel)){
            ArtDialogHlp.showInfo('提示', '固话格式不对');
            return false;
        }

        $.post('/admin/Customer/ajaxSaveCustomer',
            {
                id : id,
                name :name,
                cid : cid,
                level : level,
                type : type,
                company_name : company_name,
                product_name : product_name,
                mobile : mobile,
                tel : tel,
                wechat : wechat,
                qq : qq,
                second_cid : second_cid
            }, function(data){
                if(data.Code == 999) {
                    ArtDialogHlp.showInfo('提示', '操作成功', function(){
                        window.location.href = '/admin/Customer/customerList';
                    });
                } else {
                    ArtDialogHlp.showInfo('提示', data.Msg);
                }
            }, 'json');
    });


    function change_cid(v) {
        $.post('/admin/customer/ajaxGetCate', {pid:v}, function (data) {
            console.log(data);
            $('#second_cid').html(data);
        },'html');
    }

    $(function () {
        //终止服务保存
        $('#update').click(function () {
            var customer_id = $('#customer_id').val();
            var refuse_reason = $('#refuse_reason').val();

            if(customer_id == ''){
                ArtDialogHlp.showInfo('提示', '参数错误');
                return false;
            }
            if(!refuse_reason){
                ArtDialogHlp.showInfo('提示', '请填写终止服务备注');
                return false;
            }


            $.post("/admin/customer/customerRefuse", {customer_id:customer_id, refuse_reason:refuse_reason}, function(_data) {
                $('#myModal').modal('hide');
                if(_data.Code == 999) {
                    ArtDialogHlp.showInfo('提示', '操作成功', function(){
                        window.location.href = '/admin/customer/customerList';
                    });
                } else {
                    ArtDialogHlp.showInfo('提示', _data.Msg);
                }
            },'json');
        });

    })
</script>